package com.haitaoit.chengquan.module.center.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.center.model.MyPointModel;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by Administrator on 2016/10/10.
 */
public class MyPointAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<MyPointModel> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MyPointAdapter(Context context) {
        this.context = context;
    }

    public List<MyPointModel> getList() {
        return list;
    }

    public void setList(List<MyPointModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_point_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.point_name.setText(list.get(position).getName());
        holder.point_time.setText(list.get(position).getAddtime());
        holder.point_num.setText(list.get(position).getIntegral());
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.point_name)
        TextView point_name;
        @ViewInject(R.id.point_time)
        TextView point_time;
        @ViewInject(R.id.point_num)
        TextView point_num;
    }
}
